var status=false;
var timer;
function fly(){
	var s=$("#music_sprite");
	var offset = $(s).offset();
	if(offset.top<0){
		window.clearTimeout(timer);
		$("#music_sprite").fadeOut();
		return;
	}
	$(s).css({ top:offset.top-15, left:offset.left+0.5 });
	timer=window.setTimeout("fly();",25);
}

$(document).ready(function(){
	
	$(".song-name").popover();
	
	$("#next-page-bar").click(function(){
		var me=$(this);
		var totalPage=parseInt($(me).attr("data-tpg"));
		var tagName=$(me).attr("data-tag");
		var page=parseInt($(me).attr("data-page"))+1;
		if(page>=totalPage){
			page=totalPage;
		}
		$.get(contentPath+"/song/tag/"+tagName+"/"+page, function(data){
			$("#song-item-list").append(data);
			$(".song-name").popover();
  			$(me).attr("data-page",page);
  			if(page>=totalPage){
  				$(me).remove();
  			}
		});
	});
	
	$(".test_player_bar").live('click', function() {
		var songurl=$(this).attr("song-data");
		var songname=$(this).attr("name-data");
		var songid=$(this).attr("id-data");
		if($("#music_sprite").length==0){
			var sprite=$("<div id='music_sprite'></div>");
			$("body").append(sprite);
		}else{
			$("#music_sprite").show();
		}
		var offset = $(this).offset();
		$("#music_sprite").css({ top:offset.top - $(this).height() + "px", left:offset.left });
		fly();
		if(status==true){
			$("#topbar-player_hidden").jPlayer("setMedia",{mp3:songurl}).jPlayer("play");
		}else{
		    $.miniPlayer();
			$("#topbar-player_hidden").jPlayer({
				ready: function (event) {
					$(this).jPlayer("setMedia", {
						mp3:songurl
					}).jPlayer("play");
					status=true;
				},
				swfPath: staticServer+"/static/js/jplayer",
				supplied: "mp3",
				wmode: "window"
			});
		}
		$(".jp-song-name").html(songname);
		document.title="歌曲《"+songname+"》播放中...";
		$.get(contentPath+"/song/updatelistening/"+songid);
	});
	
});